export const get = (url, data = {}, header = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: 'GET',
			data: data,
			header: {
				'Content-Type': 'application/x-www-form-urlencoded',
				...header
			},
			success: (res) => {
				let data = res.data
				if (data.code === 200) {
					resolve(data)
				} else {
					reject(data)
				}
			},
			fail: (error) => {
				reject(error)
			}
		})
	})
}

export const post = (url, data = {}, header = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: 'POST',
			data: data,
			header: {
				'Content-Type': 'application/x-www-form-urlencoded',
				...header
			},
			success: (res) => {
				let data = res.data
				if (data.code === 200) {
					resolve(data)
				} else {
					reject(data)
				}
			},
			fail: (error) => {
				reject(error)
			}
		})
	})
}

export const uploadFile = (url, filePath, name = 'file') => {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			filePath: filePath,
			name: name,
			header: {},
			success: (res) => {
				let data = res.data
				data = JSON.parse(data)
				if (data.code === 200) {
					resolve(data)
				} else {
					reject(data)
				}
			},
			fail: (error) => {
				reject(error)
			}
		});
	})
}